package com.qding.park.manager.service.statis.facade.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qding.park.common.core.exceptions.BaseException;
import com.qding.park.manager.common.pojo.ParkDataResult;
import com.qding.park.manager.facade.statis.service.CarlockStatisFacade;
import com.qding.park.manager.facade.statis.service.InviteStatisFacade;
import com.qding.park.manager.facade.statis.service.MonthStatisFacade;
import com.qding.park.manager.facade.statis.service.OrderInfoStatisFacade;
import com.qding.park.manager.facade.statis.service.ReserveStatisFacade;
import com.qding.park.manager.facade.statis.service.TempPayStatisFacade;
import com.qding.park.manager.pojo.enums.OrderServiceType;

@Service("orderInfoStatisFacade")
public class OrderInfoStatisFacadeImpl implements OrderInfoStatisFacade {
    private static final Logger _log = LoggerFactory.getLogger(OrderInfoStatisFacadeImpl.class); 

	@Autowired
	private InviteStatisFacade inviteStatisFacade;

	@Autowired
	private CarlockStatisFacade carlockStatisFacade;

	@Autowired
	private MonthStatisFacade monthStatisFacade;

	@Autowired
	private TempPayStatisFacade tempPayStatisFacade;

	@Autowired
	private ReserveStatisFacade reserveStatisFacade;

	@Override
	public ParkDataResult orderInfo(String orderId) throws BaseException {

		if (orderId.startsWith(OrderServiceType.CARLOCK.getTag())) {
			// 锁车
			ParkDataResult parkDataResult = carlockStatisFacade.orderInfoById(orderId);
			if (!parkDataResult.getData().isEmpty()) {
				parkDataResult.putDataOnObj("orderType", OrderServiceType.CARLOCK.getType());
			}
			return parkDataResult;
		} else if (orderId.startsWith(OrderServiceType.INVITE.getTag())) {
			// 邀请
			ParkDataResult parkDataResult = inviteStatisFacade.orderInfoById(orderId);
			if (!parkDataResult.getData().isEmpty()) {
				parkDataResult.putDataOnObj("orderType", OrderServiceType.INVITE.getType());
			}
			return parkDataResult;
		} else if (orderId.startsWith(OrderServiceType.MONTHRENT.getTag())) {
			// 月租
			ParkDataResult parkDataResult = monthStatisFacade.orderInfoById(orderId);
			if (!parkDataResult.getData().isEmpty()) {
				parkDataResult.putDataOnObj("orderType", OrderServiceType.MONTHRENT.getType());
			}
			return parkDataResult;
		} else if (orderId.startsWith(OrderServiceType.RESERVER.getTag())) {
			// 预定
			ParkDataResult parkDataResult = reserveStatisFacade.orderInfoById(orderId);
			if (!parkDataResult.getData().isEmpty()) {
				parkDataResult.putDataOnObj("orderType", OrderServiceType.RESERVER.getType());
			}

			return parkDataResult;
		} else if (orderId.startsWith(OrderServiceType.TEMP_PAY.getTag())) {
			// 临停
			ParkDataResult parkDataResult = tempPayStatisFacade.orderInfoById(orderId);
			if (!parkDataResult.getData().isEmpty()) {
				parkDataResult.putDataOnObj("orderType", OrderServiceType.TEMP_PAY.getType());
			}
			return parkDataResult;
		}

		return ParkDataResult.createEmpty();
	}

}
